package com.qlhx.service.impl;

import com.qlhx.dao.BaseMemberMapper;
import com.qlhx.dao.BaseMiddleMapper;
import com.qlhx.dao.BaseVisitorMapper;
import com.qlhx.model.BaseMember;
import com.qlhx.model.BaseMiddle;
import com.qlhx.model.BaseVisitor;
import com.qlhx.service.BaseMiddleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


/**
 * Create by byl
 *
 * @versio 1.0.0
 * @Author baiyanlong
 * @date 2019/7/27 15:26
 * @description desc:
 */
@Service
public class BaseMiddleServiceImpl implements BaseMiddleService {

    @Autowired
    private BaseMiddleMapper baseMiddleMapper;

    @Autowired
    private BaseMemberMapper baseMemberMapper;

    @Autowired
    private BaseVisitorMapper baseVisitorMapper;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return baseMiddleMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(BaseMiddle record) {
        return baseMiddleMapper.insert(record);
    }

    @Override
    public int insertSelective(BaseMiddle record) {
        return baseMiddleMapper.insertSelective(record);
    }

    @Override
    public BaseMiddle selectByPrimaryKey(Integer id) {
        return baseMiddleMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(BaseMiddle record) {
        return baseMiddleMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(BaseMiddle record) {
        return baseMiddleMapper.updateByPrimaryKey(record);
    }

    @Override
    public List selectPersonByGroupId(Integer groupId) {
        List<BaseMiddle> baseMiddles = baseMiddleMapper.selectPersonByGroupId(groupId);
        StringBuffer buffer = new StringBuffer();
        StringBuffer visitor = new StringBuffer();
        for (BaseMiddle middle : baseMiddles) {
            if (middle.getType() == 1) {
                buffer.append(middle.getPersonId() + ",");
            } else if (middle.getType() == 2) {
                visitor.append(middle.getPersonId() + ",");
            }
        }
        String member = visitor.deleteCharAt(visitor.length() - 1).toString();
        String vistor = buffer.deleteCharAt(buffer.length() - 1).toString();
        List<BaseMember> byids = baseMemberMapper.findByids(member);
        List<BaseVisitor> byids1 = baseVisitorMapper.findByids(vistor);
        List arrayList = new ArrayList(byids);
        arrayList.addAll(byids1);
        return arrayList;

    }
}
